import fs from 'fs'

export const getToken = (authorization: string) => authorization?.split(' ')?.[1]?.split('_')?.[0]

export const getResult = <T>(code: 200 | 500, msg: string, data?: T) => ({ code, msg, data })

export const readData = (): MOCK.DB => {
  const data = fs.readFileSync('mock/_db.json', 'utf-8')
  return JSON.parse(data)
}

export const writeData = (data: MOCK.DB) => {
  fs.writeFileSync('mock/_db.json', JSON.stringify(data, undefined, 2), 'utf-8')
}
